//
//  HTTabBarController.m
//  今日话题
//
//  Created by lanou3g on 15/12/2.
//  Copyright © 2015年 郭海林. All rights reserved.
//

#import "HTTabBarController.h"
#import "HTNavigationController.h"
#import "AppDelegate.h"
#import "HTViewController.h"
@interface HTTabBarController ()

@end

@implementation HTTabBarController


#pragma mark - controller 方法

- (void)viewDidLoad {
    [super viewDidLoad];
    // 初始化全部自控制器
    [self setupAllChildController];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 自定义方法

// 初始化全部子控制器
- (void)setupAllChildController {
    // 初始化新闻控制器
    HTViewController *newsVC = [[HTViewController alloc] init];
    [self setupOneChildControllerWithViewController:newsVC image:[UIImage imageNamed:@"night_tabbar_icon_news_normal"] selectedImage:[UIImage imageNamed:@"night_tabbar_icon_news_highlight"] title:@"新闻"];
    // 初始化游戏控制器
    UIViewController *gameVC = [[UIViewController alloc] init];
    [self setupOneChildControllerWithViewController:gameVC image:[UIImage imageNamed:@"night_tabbar_icon_media_normal"] selectedImage:[UIImage imageNamed:@"night_tabbar_icon_media_highlight"] title:@"游戏"];
    // 初始化爆料控制器
    UIViewController *intrestsVC = [[UIViewController alloc] init];
    [self setupOneChildControllerWithViewController:intrestsVC image:[UIImage imageNamed:@"night_tabbar_icon_reader_normal"] selectedImage:[UIImage imageNamed:@"night_tabbar_icon_reader_highlight"] title:@"爆料"];
    // 初始化我的控制器
    UIViewController *meVC = [[UIViewController alloc] init];
    [self setupOneChildControllerWithViewController:meVC image:[UIImage imageNamed:@"night_tabbar_icon_me_normal"] selectedImage:[UIImage imageNamed:@"night_tabbar_icon_me_highlight"] title:@"我的"];
    self.meVC = meVC;
}

// 初始化一个子控制器
- (void)setupOneChildControllerWithViewController:(UIViewController *)vc image:(UIImage *)image selectedImage:(UIImage *)selectedImage title:(NSString *)title {
    vc.view.backgroundColor = [UIColor whiteColor];
    vc.tabBarItem.image = image;
    vc.tabBarItem.selectedImage = selectedImage;
    vc.title = title;
    vc.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"菜单" style:UIBarButtonItemStylePlain target:self action:@selector(openOrCloseLeftList)];
    NSMutableDictionary *mDic = [NSMutableDictionary dictionary];
    mDic[NSForegroundColorAttributeName] = [UIColor redColor];
    [vc.tabBarItem setTitleTextAttributes:mDic forState:UIControlStateSelected];
    HTNavigationController *nav = [[HTNavigationController alloc] initWithRootViewController:vc];
    nav.title = title;
    [self addChildViewController:nav];
}

- (void) openOrCloseLeftList
{
    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    
    if (tempAppDelegate.leftMenu.closed)
    {
        [tempAppDelegate.leftMenu openLeftView];
    }
    else
    {
        [tempAppDelegate.leftMenu closeLeftView];
    }
}
@end
